package com.hc.bankonline.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hc.bankonline.services.BankOnlineservices;
import com.hc.bankonline.services.BankOnlineservicesImpl;

public class BankOnlineLoginServlet extends HttpServlet {

	private static final long serialVersionUID = -495204792426324598L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String loginAccount = request.getParameter("loginAccount");
		String loginPassword = request.getParameter("loginPassword");
		System.out.println("账号是:" + loginAccount + "密码是:" + loginPassword);
		
		BankOnlineservices bankOnlineBiz = new BankOnlineservicesImpl();
		Map<String, Object> mapAcount = bankOnlineBiz.findLoginInfo(loginAccount, loginPassword);
		
		if(!mapAcount.isEmpty()){
			request.getSession().setAttribute("mapAcount", mapAcount);
			request.getRequestDispatcher("index.jsp").forward(request, response);
		}else{
			request.setAttribute("errorMsg", "账号或密码错误!");
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}
		
	}

}
